package com.wxtf.platform.main.employee;

import java.util.*;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.wxtf.platform.interfaces.CommonsCallProvider;
import com.wxtf.platform.plugins.user.UserBean;
import com.wxtf.platform.supers.LogicBase;
import com.wxtf.platform.tools.AccessDataBaseUtil;
import com.wxtf.platform.tools.ConstantInfoHelper;
import com.wxtf.platform.tools.FormatUtil;

/**
 * <li>Title: EmpJobMobilityAction.java</li>
 * <li>Project: baseplatform</li>
 * <li>Package: com.wxtf.platform.main.employee</li>
 * <li>Description: 人员婚姻变更 </li>
 * <li>Copyright: Copyright (c) 2012</li>
 * <li>Company: wxthtf Technologies </li>
 * <li></li>
 *
 * @author ma_wenping
 * @version 1.0.0.0
 *
 */
public class EmpMaritalAction extends LogicBase implements CommonsCallProvider{
	private static final Log log = LogFactory.getLog(EmpMaritalAction.class);

	public EmpMaritalAction(String jsonArray){

	}

	@Override
	public Object run() {
		Object msg = "";
		try {
			if("queryPage".equals(this.getMethodName())) {
				msg = this.select(this.getLogicData());
			} else if("update_mar".equals(this.getMethodName())) {
				msg = this.update(this.getLogicData());
			} else if("queryPage_chl".equals(this.getMethodName())) {
				msg = this.select_chl(this.getLogicData());
			} else {
				msg = "\"没有【" + this.getMethodName() + "】该方法\"";
			}

			if(msg == null || "[null]".equals(msg) || "null".equals(msg)) {
				msg = "\"\"";
			}
			if(msg.toString().startsWith("{") || msg.toString().startsWith("[")){
				return msg;
			}
			msg = ConstantInfoHelper.generateJSONString(msg.toString());
		} catch(Exception e) {
			msg = ConstantInfoHelper.generateErrorJSONString();
			log.error(e, e);
		} finally {
			this.clear();
		}
		return msg.toString();
	}

	@Override
	public Object delete(Object jsonArray) throws Exception {
		return null;
	}

	@Override
	public Object insert(Object jsonArray) throws Exception {
		return null;
	}

	@Override
	public Object recordCount(Object jsonArray) throws Exception {
		return null;
	}

	@Override
	public Object select(Object jsonArray) throws Exception {
		UserBean user = (UserBean) this.getRequest().getSession().getAttribute("userBean");
		sql = "from tb_employee s,tb_family_base t where s.tbe_id = t.tbe_id and s.tbe_employment_forms <> '31' ";
		boolean flag = false;
		JSONArray array = JSONArray.fromObject(jsonArray);
		if(array.size() > 0) {
			JSONObject jsonObject = JSONObject.fromObject(array.getString(0));
			String types = jsonObject.getString("types");

			if("init".equals(types)) {// 初始查询
				sql += " and s.org_id in (" + user.getCurSubOrgId() + ")";
			} else if("serch1".equals(types)) {// 条件查询
				String orgIds = jsonObject.getString("orgIds");//机构ID串
				String tbe_name = jsonObject.getString("tbe_name");//姓名
				String tbe_idcard = jsonObject.getString("tbe_idcard");//身份证
				String tbe_marital_status = jsonObject.getString("tbe_marital_status");//婚姻状态
				String tbfi_spouse_is_join = jsonObject.getString("tbfi_spouse_is_join");//是否一汽
				String tbfi_children_num = jsonObject.getString("tbfi_children_num");//家庭子女数

				StringBuffer buff = new StringBuffer();
				if(StringUtils.isNotBlank(orgIds)) {
					buff.append(" and s.org_id in (").append(user.getCurSubOrgIds(orgIds)).append(")");
				}
				if(StringUtils.isNotBlank(tbe_marital_status)) {
					if(!"0".equals(tbe_marital_status)) {//全部
						buff.append(" and s.tbe_marital_status = '").append(tbe_marital_status).append("'");
					}
				}
				if(StringUtils.isNotBlank(tbfi_spouse_is_join)) {
					if(!"2".equals(tbfi_spouse_is_join)) {//全部
						buff.append(" and t.tbfi_spouse_is_join = '").append(tbfi_spouse_is_join).append("'");
					}
				}
				if(StringUtils.isNotBlank(tbfi_children_num)) {
					buff.append(" and t.tbfi_children_num = '").append(tbfi_children_num).append("'");
				}
				if(StringUtils.isNotBlank(tbe_name)) {
					buff.append(" and s.tbe_name like '%").append(tbe_name).append("%'");
				}
				/*
				if(StringUtils.isNotBlank(tbe_idcard)) {
					buff.append(" and s.tbe_idcard like '%").append(tbe_idcard).append("%'");
				}
				 */
				if(StringUtils.isNotBlank(tbe_idcard)) {
					if(!"2".equals(tbe_idcard)){
						if("1".equals(tbe_idcard)){//是
							buff.append(" and s.reserve5 = '").append(tbe_idcard).append("'");
						} else {
							buff.append(" and (s.reserve5 <> '1' or s.reserve5 is null)");
						}
					}
				}
				sql += buff.toString();
			} else if("serch2".equals(types)) {// 高级查询
				flag = true;
				String where = jsonObject.getString("where");//机构ID串
				
				sql = " from ( SELECT s.reserve5 as r5,s.tbe_id,s.org_id,s.reserve1 AS org_name,s.tbe_idcard,s.tbe_work_permit,s.tbe_name,s.tbe_sex,s.tbe_age,s.tbe_birthday,s.tbe_native_palce,s.tbe_family_phone,s.tbe_address,s.tbe_marital_status,s.tbe_marital_condition,s.tbe_is_again_birth,s.tbe_is_barrenness,s.tbe_married_time,s.tbe_marriage_certificate,s.tbe_is_late_marriage,s.tbe_is_late_birth,s.tbe_status,t.tbfi_id,t.tbe_spouse_id,t.tbfi_spouse_name,t.tbfi_spouse_sex,t.tbfi_spouse_age,t.tbfi_spouse_birthday,t.tbfi_spouse_idcard,t.tbfi_spouse_department,t.tbfi_spouse_position,t.tbfi_spouse_is_join,t.tbfi_phone,t.tbfi_mobile,t.tbfi_address,t.tbfi_peo_num,t.tbfi_children_num,t.tbfi_children_mnum,t.tbfi_children_fnum,t.tbfi_memo,t.tbfi_valid,t.reserve1,t.reserve2,t.reserve3,t.reserve4,t.reserve5,t.create_by,t.create_time,t.last_modify_by,t.last_modify_time FROM tb_employee s, tb_family_base t WHERE s.tbe_id = t.tbe_id AND s.tbe_employment_forms <> '31' and s.org_id in (" + user.getCurSubOrgId() + ")) aa where 1 = 1";
				sql += where;
			}
		}

		// 排序
		String sortname = this.getRequest().getParameter("sortname");
		String sortorder = this.getRequest().getParameter("sortorder");
		if(sortname != null && sortname != null) {
			if(flag){
				sql += " order by aa." + sortname + " " + sortorder;
			} else {
				if("org_name".equals(sortname)) {
					sql += " order by s.reserve1 " + sortorder;
				} else {
					if("tbfi_children_num".equals(sortname) || "tbfi_children_mnum".equals(sortname) || "tbfi_children_fnum".equals(sortname)){
						sql += " order by t." + sortname + " " + sortorder;
					} else {
						sql += " order by s." + sortname + " " + sortorder;
					}
				}
			}
		}

		String countSql = "select count(*) " + sql;
		String querySql = "select s.reserve5 as r5,s.tbe_id,s.org_id,s.reserve1 as org_name,s.tbe_idcard,s.tbe_work_permit,s.tbe_name,s.tbe_sex,s.tbe_age,s.tbe_birthday,s.tbe_native_palce,s.tbe_family_phone,s.tbe_address,s.tbe_marital_status,s.tbe_marital_condition,s.tbe_is_again_birth,s.tbe_is_barrenness,s.tbe_married_time,s.tbe_marriage_certificate,s.tbe_is_late_marriage,s.tbe_is_late_birth,s.tbe_status,t.tbfi_id,t.tbe_spouse_id,t.tbfi_spouse_name,t.tbfi_spouse_sex,t.tbfi_spouse_age,t.tbfi_spouse_birthday,t.tbfi_spouse_idcard,t.tbfi_spouse_department,t.tbfi_spouse_position,t.tbfi_spouse_is_join,t.tbfi_phone,t.tbfi_mobile,t.tbfi_address,t.tbfi_peo_num,t.tbfi_children_num,t.tbfi_children_mnum,t.tbfi_children_fnum,t.tbfi_memo,t.tbfi_valid,t.reserve1,t.reserve2,t.reserve3,t.reserve4,t.reserve5,t.create_by,t.create_time,t.last_modify_by,t.last_modify_time " + sql;
		if(flag) {
			countSql = "select count(*) " + sql;
			querySql = "select aa.* " + sql;
		}
		String[] fields = {"emp_reserve5", "tbe_id", "org_id", "org_name", "tbe_idcard", "tbe_work_permit", "tbe_name", "tbe_sex",
				"tbe_age", "tbe_birthday", "tbe_native_palce", "tbe_family_phone", "tbe_address", "tbe_marital_status",
				"tbe_marital_condition", "tbe_is_again_birth", "tbe_is_barrenness", "tbe_married_time", "tbe_marriage_certificate", "tbe_is_late_marriage",
				"tbe_is_late_birth", "tbe_status", "tbfi_id", "tbe_spouse_id", "tbfi_spouse_name", "tbfi_spouse_sex",
				"tbfi_spouse_age", "tbfi_spouse_birthday", "tbfi_spouse_idcard", "tbfi_spouse_department",
				"tbfi_spouse_position", "tbfi_spouse_is_join", "tbfi_phone", "tbfi_mobile", "tbfi_address",
				"tbfi_peo_num", "tbfi_children_num", "tbfi_children_mnum", "tbfi_children_fnum", "tbfi_memo","tbfi_valid",
				"reserve1", "reserve2", "reserve3", "reserve4", "reserve5", "create_by", "create_time",
				"last_modify_by", "last_modify_time" };
		
		return AccessDataBaseUtil.query4SQLPagging(fields, countSql, querySql, this.getPage(), this.getPagesize(), null);
	}

	@Override
	public Object update(Object jsonArray) throws Exception {
		UserBean user = (UserBean) this.getRequest().getSession().getAttribute("userBean");
		String curTime = FormatUtil.getCurentDateTime();

		JSONArray array = JSONArray.fromObject(jsonArray);
		JSONObject jsonObject = JSONObject.fromObject(array.getString(0));
		
		String marital_status = jsonObject.getString("tbe_marital_status_text");//婚姻状态
		String tbe_id = jsonObject.getString("tbe_id");//员工ID
		String tbe_spouse_id = jsonObject.getString("tbe_spouse_id");//员工配偶ID
		String tbfi_spouse_idcard = jsonObject.getString("tbfi_spouse_idcard");//配偶身份证
		String isNotsame = jsonObject.getString("tbfi_spouse_is_join");//是否一汽员工
		String emp_reserve5 = jsonObject.getString("emp_reserve5");//本季结婚
		
		int mnum = Integer.valueOf(jsonObject.getString("tbfi_children_mnum"));//男孩数
		int fnum = Integer.valueOf(jsonObject.getString("tbfi_children_fnum"));//女孩数
		
		String sex1 = jsonObject.getString("tbe_sex");//员工性别
		String tbfi_valid1 = "女".equals(sex1)? "1": "0";//家庭是否有效-员工
		String tbfi_valid2 = "1".equals(tbfi_valid1)? "0" : "1";//家庭是否有效-配偶
		if(!"1".equals(isNotsame)) {// 判断配偶是否为一汽员工
			tbfi_valid1 = "1";
		}
		
		List<String> listSql = new ArrayList<String>();
		StringBuffer buff1 = new StringBuffer();//员工信息
		StringBuffer buff2 = new StringBuffer();//员工家庭
		StringBuffer buff3 = new StringBuffer();//配偶信息
		StringBuffer buff4 = new StringBuffer();//配偶家庭
		
		//当将子女数从1更改为其他数量时
		sql = "select tbfi_children_num from tb_family_base where tbe_id = ?";
		List<Object> l1 = AccessDataBaseUtil.query4List(sql, new Object[]{ tbe_id });
		String tbfi_children_num = l1.get(0).toString();
		if("1".equals(tbfi_children_num)){
			String tbfi_children_num1 = jsonObject.getString("tbfi_children_num");
			if(!"1".equals(tbfi_children_num1)){
				sql = "select count(*) from tb_family_base s,tbe_only_child_record t where s.TBFI_ID = t.TBFI_ID and t.RESERVE2 <> '1' and s.TBE_ID = ?";
				int cnt = AccessDataBaseUtil.queryForInt(sql, new Object[]{ tbe_id });
				if(cnt > 0){
					return "{\"result\":false,\"resultmessage\":\"调用失败\",\"resultrecord\":\"操作失败，请先删除“独生子女证”再更改子女数量\"}";
				}
			}
		}
		
		//验证配偶选择的合法性
		sql = "select tbe_idcard from tb_employee  where tbe_id = ?";
		List<Object> l = AccessDataBaseUtil.query4List(sql, new Object[]{ tbe_id });
		String tbe_idcard = l.get(0).toString();
		if(tbe_idcard.equals(tbfi_spouse_idcard)){
			return "{\"result\":false,\"resultmessage\":\"调用失败\",\"resultrecord\":\"操作失败，配偶身份证号不能与其本人相同\"}";
		}
		if("1".equals(isNotsame)){//配偶是一汽员工
			if(StringUtils.isBlank(tbe_spouse_id)){
				return "{\"result\":false,\"resultmessage\":\"调用失败\",\"resultrecord\":\"操作失败，请选择配偶（一汽员工）\"}";
			}
			sql = "select count(*) from tb_family_base where tbe_spouse_id = ? and tbe_id <> ?";
			int cnt = AccessDataBaseUtil.queryForInt(sql, new Object[]{tbe_spouse_id, tbe_id });
			if(cnt > 0){
				return "{\"result\":false,\"resultmessage\":\"调用失败\",\"resultrecord\":\"操作失败，配偶已经被选择过\"}";
			}
			sql = "select count(*) from tb_family_base where tbe_id = ? and tbfi_spouse_idcard is not null and tbfi_spouse_idcard <> ?";
			cnt = AccessDataBaseUtil.queryForInt(sql, new Object[]{ tbe_spouse_id, tbfi_spouse_idcard });
			if(cnt > 1){
				return "{\"result\":false,\"resultmessage\":\"调用失败\",\"resultrecord\":\"操作失败，配偶已经被选择过\"}";
			}
		}
		
		sql = "select tbfi_children_mnum,tbfi_children_fnum from tb_family_base where tbe_id = ?";//tbe_id tbe_spouse_id
		List<Object[]> list = AccessDataBaseUtil.query(sql, new Object[]{ tbe_id });
		Object[] obj = list.get(0);
		int mnum1 = Integer.valueOf(obj[0].toString());
		int fnum1 = Integer.valueOf(obj[1].toString());
		if((mnum + fnum) != (mnum1 + fnum1) && (mnum + fnum) > 1) {
			sql = "select count(*) from tbe_only_child_record where tbfi_id in (select tbfi_id from tb_family_base where tbe_id = ? or tbe_spouse_id = ?) and reserve2 <> '1' ";
			int cnt = AccessDataBaseUtil.queryForInt(sql, new Object[]{ tbe_id, tbe_id });
			if(cnt > 0){
				return "{\"result\":false,\"resultmessage\":\"调用失败\",\"resultrecord\":\"操作失败：该家庭办理过独生子女证,请先退证,然后修改家庭信息\"}";
			}
		}
		
		// 判断婚姻状态
		if("已婚".equals(marital_status) || "再婚".equals(marital_status)) {
			if("1".equals(isNotsame)) {// 判断配偶是否为一汽员工
				//修改配偶的家庭信息，并填写相应的配偶信息（员工信息）
				buff4.append("update tb_family_base set tbfi_valid='").append(tbfi_valid2).append("',")
					.append("tbe_spouse_id='").append(tbe_id).append("',")
					.append("tbfi_spouse_name='").append(jsonObject.getString("tbe_name")).append("',")
					.append("tbfi_spouse_sex='").append(jsonObject.getString("tbe_sex")).append("',")
					.append("tbfi_spouse_age=").append(StringUtils.isBlank(jsonObject.getString("tbe_age")) ? "0" : jsonObject.getString("tbe_age")).append(",")
					.append("tbfi_spouse_birthday='").append(jsonObject.getString("tbe_birthday")).append("',")
					.append("tbfi_spouse_idcard='").append(jsonObject.getString("tbe_idcard")).append("',")
					.append("tbfi_spouse_department='").append(jsonObject.getString("reserve1")).append("',")
					.append("tbfi_spouse_position='").append(jsonObject.getString("tbe_position")).append("',")
					.append("tbfi_spouse_is_join='1',")
					.append("tbfi_children_num=").append(jsonObject.getString("tbfi_children_num"))
					.append(",tbfi_children_mnum=").append(jsonObject.getString("tbfi_children_mnum"))
					.append(",tbfi_children_fnum=").append(jsonObject.getString("tbfi_children_fnum"))
					.append(",last_modify_by='").append(user.getUserId()).append("',")
					.append("last_modify_time='").append(curTime).append("'")
					.append(" where tbe_id = '").append(tbe_spouse_id).append("'");
				
				//更改配偶员工表中婚姻信息
				buff3.append("update tb_employee set tbe_marital_status='").append(jsonObject.getString("tbe_marital_status"))
					.append("',tbe_married_time='").append(jsonObject.getString("tbe_married_time"))
					.append("',tbe_marriage_certificate='").append(jsonObject.getString("tbe_marriage_certificate"))
					.append("',reserve5='").append(emp_reserve5)
					.append("' where tbe_id='").append(tbe_spouse_id).append("'");
				listSql.add(buff4.toString());
				listSql.add(buff3.toString());
			}
			//修改员工的家庭信息
			buff2.append("update tb_family_base set tbfi_valid = '").append(tbfi_valid1).append("',")
				.append("tbfi_spouse_name='").append(jsonObject.getString("tbfi_spouse_name"))
				.append("',tbe_spouse_id='").append(jsonObject.getString("tbe_spouse_id"))
				.append("',tbfi_spouse_sex='").append(jsonObject.getString("tbfi_spouse_sex"))
				.append("',tbfi_spouse_age=").append(StringUtils.isBlank(jsonObject.getString("tbfi_spouse_age")) ? "0" : jsonObject.getString("tbfi_spouse_age"))
				.append(",tbfi_spouse_birthday='").append(jsonObject.getString("tbfi_spouse_birthday"))
				.append("',tbfi_spouse_idcard='").append(jsonObject.getString("tbfi_spouse_idcard"))
				.append("',tbfi_spouse_department='").append(jsonObject.getString("tbfi_spouse_department"))
				.append("',tbfi_spouse_position='").append(jsonObject.getString("tbfi_spouse_position"))
				.append("',tbfi_spouse_is_join='").append(isNotsame)
				.append("',tbfi_phone='").append(jsonObject.getString("tbfi_phone"))
				.append("',tbfi_mobile='").append(jsonObject.getString("tbfi_mobile"))
				.append("',tbfi_address='").append(jsonObject.getString("tbfi_address"))
				.append("',tbfi_children_num=").append(jsonObject.getString("tbfi_children_num"))
				.append(",tbfi_children_mnum=").append(jsonObject.getString("tbfi_children_mnum"))
				.append(",tbfi_children_fnum=").append(jsonObject.getString("tbfi_children_fnum"))
				.append(",tbfi_memo='").append(jsonObject.getString("tbfi_memo"))
				.append("',last_modify_by='").append(user.getUserId())
				.append("',last_modify_time='").append(curTime)
				.append("' where tbe_id ='").append(tbe_id).append("'");
			
			buff1.append("update tb_employee set tbe_marital_status='").append(jsonObject.getString("tbe_marital_status"))
				.append("',tbe_married_time='").append(jsonObject.getString("tbe_married_time"))
				.append("',tbe_marriage_certificate='").append(jsonObject.getString("tbe_marriage_certificate"))
				.append("',tbe_is_late_marriage='").append(jsonObject.getString("tbe_is_late_marriage"))
				.append("',reserve5='").append(emp_reserve5)
				.append("' where tbe_id='").append(tbe_id).append("'");
			
			listSql.add(buff2.toString());
			listSql.add(buff1.toString());
		} else if("离异".equals(marital_status)) {
			// 判断配偶是否为一汽员工
			if("1".equals(isNotsame)) {
				//配偶家庭中的配偶信息为空，并使配偶家庭可用
				buff4.append("update tb_family_base set tbfi_valid='1'")
					.append(",tbe_spouse_id='',tbfi_spouse_name=''")
					.append(",tbfi_spouse_age=0,tbfi_spouse_birthday='',tbfi_spouse_idcard=''")
					.append(",tbfi_spouse_department='',tbfi_spouse_position='',tbfi_spouse_is_join='0'")
					.append(",last_modify_by='").append(user.getUserId())
					.append("',last_modify_time='").append(curTime)
					.append("' where tbe_id='").append(tbe_spouse_id).append("'");
				
				//更改员工表中信息
				buff3.append("update tb_employee set tbe_marital_status='").append(jsonObject.getString("tbe_marital_status"))
						.append("',tbe_married_time='',tbe_marriage_certificate='',last_modify_by='").append(user.getUserId())
						.append("',last_modify_time='").append(curTime)
						.append("',reserve5='").append(emp_reserve5)
						.append("' where tbe_id='").append(tbe_spouse_id).append("'");
				listSql.add(buff4.toString());
				listSql.add(buff3.toString());
			}
			buff2.append("update tb_family_base set tbfi_valid='1',tbe_spouse_id='',tbfi_spouse_name='',tbfi_spouse_age=0,tbfi_spouse_birthday='',tbfi_spouse_idcard=''")
				.append(",tbfi_spouse_department='',tbfi_spouse_is_join='0',tbfi_spouse_position=''")
				.append(",tbfi_phone='").append(jsonObject.getString("tbfi_phone")).append("'")
				.append(",tbfi_address='").append(jsonObject.getString("tbfi_address")).append("'")
				.append(",tbfi_children_num=").append(jsonObject.getString("tbfi_children_num"))
				.append(",tbfi_children_mnum=").append(jsonObject.getString("tbfi_children_mnum"))
				.append(",tbfi_children_fnum=").append(jsonObject.getString("tbfi_children_fnum"))
				.append(",tbfi_memo='").append(jsonObject.getString("tbfi_memo"))
				.append("',last_modify_by='").append(user.getUserId())
				.append("',last_modify_time='").append(curTime)
				.append("' where tbe_id ='").append(tbe_id).append("'");
			
			buff1.append("update tb_employee set tbe_marital_status='").append(jsonObject.getString("tbe_marital_status"))
				.append("',reserve5='").append(emp_reserve5)
				.append("',tbe_married_time='',tbe_marriage_certificate='' where tbe_id='").append(tbe_id).append("'");
			listSql.add(buff2.toString());
			listSql.add(buff1.toString());
		} else if("未婚".equals(marital_status)) {
			//配偶信息清空、婚姻信息清空
			buff2.append("update tb_family_base set tbfi_valid='1',tbfi_spouse_name='',tbfi_spouse_age=0,tbfi_spouse_birthday='',tbfi_spouse_idcard='',")
				.append("tbfi_spouse_department='',tbfi_spouse_is_join='0',tbfi_spouse_position='',")
				.append("tbfi_peo_num=1,tbfi_children_num=0,tbfi_children_mnum=0,tbfi_children_fnum=0,tbfi_memo='").append(jsonObject.getString("tbfi_memo"))
				.append("',tbfi_phone='").append(jsonObject.getString("tbfi_phone"))
				.append("',tbfi_address='").append(jsonObject.getString("tbfi_address"))
				.append("',tbfi_memo='").append(jsonObject.getString("tbfi_memo"))
				.append("',last_modify_by='").append(user.getUserId())
				.append("',last_modify_time='").append(curTime)
				.append("' where tbe_id ='").append(tbe_id).append("'");
			
			buff1.append("update tb_employee set tbe_marital_status='").append(jsonObject.getString("tbe_marital_status"))
				.append("',tbe_married_time='',tbe_marriage_certificate='',tbe_is_late_marriage='0',reserve5='0' where tbe_id='").append(tbe_id).append("'");
		
			listSql.add(buff2.toString());
			listSql.add(buff1.toString());
		} else if("丧偶".equals(marital_status)) {
			if("1".equals(isNotsame)) {// 判断配偶是否为一汽员工
				buff3.append("update tb_employee set tbe_status = '102-5',reserve5='").append(emp_reserve5)
					.append("' where tbe_id = '").append(tbe_spouse_id).append("'");
				listSql.add(buff3.toString());
			}
			
			buff2.append("update tb_family_base set tbfi_valid='1',tbfi_spouse_name='',tbfi_spouse_age=0,tbfi_spouse_birthday='',tbfi_spouse_idcard='',")
				.append("tbfi_spouse_department='',tbfi_spouse_is_join='0',tbfi_spouse_position='',")
				.append("tbfi_children_num=").append(jsonObject.getString("tbfi_children_num"))
				.append(",tbfi_children_mnum=").append(jsonObject.getString("tbfi_children_mnum"))
				.append(",tbfi_children_fnum=").append(jsonObject.getString("tbfi_children_fnum"))
				.append(",tbfi_memo='").append(jsonObject.getString("tbfi_memo"))
				.append("',tbfi_phone='").append(jsonObject.getString("tbfi_phone"))
				.append("',tbfi_address='").append(jsonObject.getString("tbfi_address"))
				.append("',tbfi_memo='").append(jsonObject.getString("tbfi_memo"))
				.append("',last_modify_by='").append(user.getUserId())
				.append("',last_modify_time='").append(curTime)
				.append("' where tbe_id ='").append(tbe_id).append("'");
			
			buff1.append("update tb_employee set tbe_marital_status = '").append(jsonObject.getString("tbe_marital_status"))
				.append("',reserve5='").append(emp_reserve5)
				.append("',tbe_married_time='',tbe_marriage_certificate='' where tbe_id = '").append(tbe_id).append("'");
			listSql.add(buff2.toString());
			listSql.add(buff1.toString());
		}
		AccessDataBaseUtil.executeSQLUpdate(listSql);
		return "\"婚姻信息变更成功\"";
	}

	String[] file_chl = { "tbfci_id", "org_id", "tbfi_id ", "tbfci_name", "tbfci_sex", "tbfci_age", "tbfci_birthday",
			"tbfci_nation", "tbfci_idcard", "tbfci_memo", "reserve1", "reserve2", "reserve3", "reserve4", "reserve5",
			"create_by", "create_time", "last_modify_by ", "last_modify_time" };

	public Object select_chl(Object jsonArray) {
		JSONArray array = JSONArray.fromObject(jsonArray);
		JSONObject jsonObject = JSONObject.fromObject(array.getString(0));
		Object[] params = { jsonObject.getString("tbfi_id") };

		String sql = "from tb_family_chindren_info where tbfi_id=?";
		String countSql = "select count(*) " + sql;
		String querySql = "select tbfci_id,org_id,tbfi_id ,tbfci_name,tbfci_sex,tbfci_age,tbfci_birthday,tbfci_nation,"
				+ "tbfci_idcard,tbfci_memo,reserve1,reserve2,reserve3,reserve4,reserve5,create_by,create_time,"
				+ "last_modify_by ,last_modify_time " + sql;
		return AccessDataBaseUtil.query4SQLPagging(file_chl, countSql, querySql, this.getPage(), this.getPagesize(), params);
	}

	public Object insert_chl(Object jsonArray) {
		JSONArray array = JSONArray.fromObject(jsonArray);
		JSONObject jsonObject = JSONObject.fromObject(array.getString(0));
		Object[] params = { jsonObject.getString("tbfi_id") };

		String sql = "from tb_family_chindren_info where tbfi_id=?";
		String countSql = "select count(*) " + sql;
		String querySql = "select tbfci_id,org_id,tbfi_id ,tbfci_name,tbfci_sex,tbfci_age,tbfci_birthday,tbfci_nation,"
				+ "tbfci_idcard,tbfci_memo,reserve1,reserve2,reserve3,reserve4,reserve5,create_by,create_time,"
				+ "last_modify_by ,last_modify_time " + sql;
		return AccessDataBaseUtil.query4SQLPagging(file_chl, countSql, querySql, this.getPage(), this.getPagesize(),
				params);
	}

	public Object update_chl(Object jsonArray) {
		JSONArray array = JSONArray.fromObject(jsonArray);
		JSONObject jsonObject = JSONObject.fromObject(array.getString(0));
		Object[] params = { jsonObject.getString("tbfi_id") };

		String sql = "from tb_family_chindren_info where tbfi_id=?";
		String countSql = "select count(*) " + sql;
		String querySql = "select tbfci_id,org_id,tbfi_id ,tbfci_name,tbfci_sex,tbfci_age,tbfci_birthday,tbfci_nation,"
				+ "tbfci_idcard,tbfci_memo,reserve1,reserve2,reserve3,reserve4,reserve5,create_by,create_time,"
				+ "last_modify_by ,last_modify_time " + sql;
		return AccessDataBaseUtil.query4SQLPagging(file_chl, countSql, querySql, this.getPage(), this.getPagesize(),
				params);
	}

	public Object delete_chl(Object jsonArray) {
		JSONArray array = JSONArray.fromObject(jsonArray);
		JSONObject jsonObject = JSONObject.fromObject(array.getString(0));
		Object[] params = { jsonObject.getString("tbfi_id") };

		String sql = "from tb_family_chindren_info where tbfi_id=?";
		String countSql = "select count(*) " + sql;
		String querySql = "select tbfci_id,org_id,tbfi_id ,tbfci_name,tbfci_sex,tbfci_age,tbfci_birthday,tbfci_nation,"
				+ "tbfci_idcard,tbfci_memo,reserve1,reserve2,reserve3,reserve4,reserve5,create_by,create_time,"
				+ "last_modify_by ,last_modify_time " + sql;
		return AccessDataBaseUtil.query4SQLPagging(file_chl, countSql, querySql, this.getPage(), this.getPagesize(),
				params);
	}

	@Override
	public Object updateBatch(Object jsonArray) throws Exception {
		return null;
	}

	@Override
	public Object onCreate(Object jsonArray) {
		return null;
	}

	@Override
	public Object onDestory(Object jsonArray) {
		return null;
	}

	@Override
	public Object onInit(Object jsonArray) {
		return null;
	}

	@Override
	public Object setRequest(HttpServletRequest request) throws Exception {
		this.request = request;
		return request;
	}
}
